package server;

/**
 *@author Adam,Aqeel
 */

import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.Vector;

import storage.RMIServer;

public class RMIStorageClient {
	String name;
	RMIServer server;
	Registry registry;
	

	public RMIStorageClient(String myName){
		name = myName;
	}

	public void begin(String location) {
		System.setSecurityManager(new RMISecurityManager());
		try {
			registry = LocateRegistry.getRegistry(location);
			server = (RMIServer)registry.lookup(name);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public Vector getSongs(){
		Vector v = null;
		try{
			 v = server.getSongs();
			System.out.println("got songs from storage");
		} catch (Exception e) {
			e.printStackTrace();
		}
		return v;
	}
	
	public int getPort(){
		int p = 333;
		try{
		p = server.getPort();
		} catch (Exception e){
			e.printStackTrace();
		}
		return p;
	}
	
	public double transmitMusicTrack(String trackName, String HifiAddress){
		try{
			 double d = server.transmitMusicTrack(trackName, HifiAddress, "5000");
			 return d;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return 0.0;
	}
	
	public void stopTransmit(){
		try {
			server.stopTransmit();
		} catch (RemoteException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
}
